﻿/* 
 * Copyright (c) 2010 Letwory Interactive
 * All rights reserved.
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * -- Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * -- Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * Original contributor: Nathan Letwory
 */

using System;

namespace VerseSharp
{
    /// <summary>
    /// Delegate for the b_dimensions_set command. Verse throws event with this form
    /// when the command has been received.
    /// </summary>
    /// <param name="command"></param>
    public delegate void BitmapDimensionsSetCallback(BitmapDimensionsSetCommand command);

    /// <summary>
    /// Command to set the dimensions for the bitmap. If the new size is smaller than the old
    /// size, the layers will be truncated. If the new size is larger than the old size, the
    /// layers will be increased and old data will stay.
    /// 
    /// Note that none of the dimension values should be 0. Setting Depth to a value larger than 1
    /// means you have a 3D bitmap.
    /// </summary>
    public class BitmapDimensionsSetCommand: IVerseCommand
    {
        /// <summary>
        /// Protocol ID of the command.
        /// </summary>
        public CommandID ID { get { return CommandID.BitmapDimensionsSet; } }
        /// <summary>
        /// ID of the node being accessed.
        /// </summary>
        public uint NodeID;
        /// <summary>
        /// Width for the bitmap. 0 is invalid.
        /// </summary>
        public ushort Width;
        /// <summary>
        /// Height for the bitmap. 0 is invalid.
        /// </summary>
        public ushort Height;
        /// <summary>
        /// Depth for the bitmap. Values higher than 1 mean a 3D bitmap. 0 is invalid.
        /// </summary>
        public ushort Depth;

        public void Deserialize(byte[] source, ref int pos)
        {
            NodeID = Utils.GetUInt32(source, ref pos);
            Width = Utils.GetUInt16(source, ref pos);
            Height = Utils.GetUInt16(source, ref pos);
            Depth = Utils.GetUInt16(source, ref pos);
        }

        public void Serialize(byte[] destination, ref int pos)
        {
            Utils.PutUInt32(destination, ref pos, NodeID);
            Utils.PutUInt16(destination, ref pos, Width);
            Utils.PutUInt16(destination, ref pos, Height);
            Utils.PutUInt16(destination, ref pos, Depth);
        }
    }
}
